var Dragging = function(validateHandler) { //参数为验证点击区域是否为可移动区域，如果是返回欲移动元素，负责返回null
	var draggingObj = null; //dragging Dialog
	var diffX = 0;
	var diffY = 0;

	function mouseHandler(e) {
		switch(e.type) {
			case 'mousedown':
				draggingObj = validateHandler(e); //验证是否为可点击移动区域
				if(draggingObj != null) {
					diffX = e.clientX - draggingObj.offsetLeft;
					diffY = e.clientY - draggingObj.offsetTop;
				}
				break;

			case 'mousemove':
				if(draggingObj) {
					e.preventDefault();
					draggingObj.style.left = (e.clientX - diffX) + 'px';
					draggingObj.style.top = (e.clientY - diffY) + 'px';
				}
				break;

			case 'mouseup':
				draggingObj = null;
				diffX = 0;
				diffY = 0;
				break;
		}
	};

	return {
		enable: function() {
			document.addEventListener('mousedown', mouseHandler);
			document.addEventListener('mousemove', mouseHandler);
			document.addEventListener('mouseup', mouseHandler);
		},
		disable: function() {
			document.removeEventListener('mousedown', mouseHandler);
			document.removeEventListener('mousemove', mouseHandler);
			document.removeEventListener('mouseup', mouseHandler);
		}
	}
}

function getDraggingDialog(e) {
    var target = e.target;
    if (target && typeof (target.className) == 'string') {
        while (target && target.className.indexOf('video') == -1) {
            target = target.offsetParent;
        }

        if (target != null) {
            return target.offsetParent;
        } else {
            return null;
        }
    }
}

Dragging(getDraggingDialog).enable();
//加载绑定视频窗口拉伸事件
function loadDrag() {
	var oDiv = document.getElementById("www_ablanuxe_com_1");
	var oDiv2 = document.getElementById("video");
	var zhezhao = document.getElementById("www_ablanuxe_com");
	var right = document.getElementById("right");
	var bottom = document.getElementById("bottom");
	var mouseStart = {};
	var divStart = {};
	var rightStart = {};
	var bottomStart = {};
	//往右拽
	right.onmousedown = function(ev) {
		var oEvent = ev || event;
		mouseStart.x = oEvent.clientX;
		mouseStart.y = oEvent.clientY;
		rightStart.x = right.offsetLeft;
		if(right.setCapture) {
			right.onmousemove = doDrag1;
			right.onmouseup = stopDrag1;
			right.setCapture();
		} else {
			document.addEventListener("mousemove", doDrag1, true);
			document.addEventListener("mouseup", stopDrag1, true);
		}
	};

	function doDrag1(ev) {
		var oEvent = ev || event;
		oEvent.preventDefault();
		var l = oEvent.clientX - mouseStart.x + rightStart.x;
		var w = l + oDiv.offsetWidth;
		if(w < oDiv.offsetWidth) {
			w = oDiv.offsetWidth;
		} else if(w > document.documentElement.clientWidth - oDiv2.offsetLeft) {
			w = document.documentElement.clientWidth - oDiv2.offsetLeft - 2;
		}
		oDiv2.style.width = w + "px";
	};

	function stopDrag1() {
		if(right.releaseCapture) {
			right.onmousemove = null;
			right.onmouseup = null;
			right.releaseCapture();
		} else {
			document.removeEventListener("mousemove", doDrag1, true);
			document.removeEventListener("mouseup", stopDrag1, true);
		}
	};
	//往下拽
	bottom.onmousedown = function(ev) {
		var oEvent = ev || event;
		mouseStart.x = oEvent.clientX;
		mouseStart.y = oEvent.clientY;
		bottomStart.y = bottom.offsetTop;
		if(bottom.setCapture) {
			bottom.onmousemove = doDrag2;
			bottom.onmouseup = stopDrag2;
			bottom.setCapture();
		} else {
			document.addEventListener("mousemove", doDrag2, true);
			document.addEventListener("mouseup", stopDrag2, true);
		}
	};

	function doDrag2(ev) {
		var oEvent = ev || event;
		oEvent.preventDefault();
		var t = oEvent.clientY - mouseStart.y + bottomStart.y;
		var h = t + oDiv.offsetHeight;
		if(h < oDiv.offsetHeight) {
			h = oDiv.offsetHeight;
		} else if(h > document.documentElement.clientHeight - oDiv2.offsetTop) {
			h = document.documentElement.clientHeight - oDiv2.offsetTop - 2;
		}
		oDiv2.style.height = h + "px";
	};

	function stopDrag2() {
		if(bottom.releaseCapture) {
			bottom.onmousemove = null;
			bottom.onmouseup = null;
			bottom.releaseCapture();
		} else {
			document.removeEventListener("mousemove", doDrag2, true);
			document.removeEventListener("mouseup", stopDrag2, true);
		}
	};
	//往左右同时拽
	oDiv.onmousedown = function(ev) {
		var oEvent = ev || event;
		mouseStart.x = oEvent.clientX;
		mouseStart.y = oEvent.clientY;
		divStart.x = oDiv.offsetLeft;
		divStart.y = oDiv.offsetTop;
		if(oDiv.setCapture) {
			oDiv.onmousemove = doDrag;
			oDiv.onmouseup = stopDrag;
			oDiv.setCapture();
		} else {
			document.addEventListener("mousemove", doDrag, true);
			document.addEventListener("mouseup", stopDrag, true);
		}
		zhezhao.style.display = 'block';
	};

	function doDrag(ev) {
		var oEvent = ev || event;
		oEvent.preventDefault();
		var l = oEvent.clientX - mouseStart.x + divStart.x;
		var t = oEvent.clientY - mouseStart.y + divStart.y;
		var w = l + oDiv.offsetWidth;
		var h = t + oDiv.offsetHeight;
		if(w < oDiv.offsetWidth) {
			w = oDiv.offsetWidth;
		} else if(w > document.documentElement.clientWidth - oDiv2.offsetLeft) {
			w = document.documentElement.clientWidth - oDiv2.offsetLeft - 2;
		}
		if(h < oDiv.offsetHeight) {
			h = oDiv.offsetHeight;
		} else if(h > document.documentElement.clientHeight - oDiv2.offsetTop) {
			h = document.documentElement.clientHeight - oDiv2.offsetTop - 2;
		}
		oDiv2.style.width = w + "px";
		oDiv2.style.height = h + "px";
	};

	function stopDrag() {
		if(oDiv.releaseCapture) {
			oDiv.onmousemove = null;
			oDiv.onmouseup = null;
			oDiv.releaseCapture();
		} else {
			document.removeEventListener("mousemove", doDrag, true);
			document.removeEventListener("mouseup", stopDrag, true);
		}
		zhezhao.style.display = 'none';
	};

};